﻿using System;
using System.Collections.Generic;
using System.Windows.Input;
using System.Text;
using MslDiary.Model;
using MFW = MslDiary.Framework;

namespace MslDiary.ViewModel
{
    public class SkinListViewModel : MslDiary.Framework.ViewModelBase
    {
        private MFW.IO.ConfigHelper config = new MFW.IO.ConfigHelper(MFW.Gloable.Config);
        public SkinListViewModel()
        {
            MslDiary.Framework.Gloable.IsSkinChanged = false;
            this.SkinList = new List<SkinModel>()
            {
                new SkinModel(){Path="/Theme/Images/Skin/default.jpg",Name="默认"},
                new SkinModel(){Path="/Theme/Images/Skin/1.jpg",Name="绚彩紫色"},
                new SkinModel(){Path="/Theme/Images/Skin/2.jpg",Name="悠然百合"},
                new SkinModel(){Path="/Theme/Images/Skin/3.jpg",Name="漫舞派对"},
                new SkinModel(){Path="/Theme/Images/Skin/4.jpg",Name="绿化环保"},
                new SkinModel(){Path="/Theme/Images/Skin/5.jpg",Name="唯美星空"},
                new SkinModel(){Path="/Theme/Images/Skin/6.jpg",Name="固若精钢"},
                new SkinModel(){Path="/Theme/Images/Skin/7.jpg",Name="原木韵味"},
                new SkinModel(){Path="/Theme/Images/Skin/9.jpg",Name="梦幻玫瑰"},
                new SkinModel(){Path="/Theme/Images/Skin/10.jpg",Name="金色秋夕"}
            };
            this.SelectedSkinIndex = this.SkinList.FindIndex(new Predicate<SkinModel>((p) =>
            {
                return p.Path.Equals(MslDiary.Framework.Gloable.AppBackgroundImage);
            }));

            this.WindowLoadCommand = new CommandBase((Object window) =>
            {
            });
            this.SkinSelectedChangedCommand = new CommandBase((Object mod) =>
            {
                if (mod != null)
                {
                    this.SkinMod = (SkinModel)mod;
                    MslDiary.Framework.Gloable.AppBackgroundImage = this.SkinMod.Path;
                    MslDiary.Framework.Gloable.IsSkinChanged = true;
                    this.config.SetValueByKey("AppBackgroundImage", this.SkinMod.Path);
                    this.config.Save();
                }
            });
        }
        #region 属性

        private int _selectedSkinIndex = 0;
        public SkinModel SkinMod { get; set; }
        public List<SkinModel> SkinList { get; set; }
        public int SelectedSkinIndex
        {
            get { return _selectedSkinIndex; }
            set
            {
                //base.SetProperty<int>(ref this._selectedSkinIndex, value);
                if (this._selectedSkinIndex == value)
                    return;
                this._selectedSkinIndex = value;
                this.RaisePropertyChanged("SelectedSkinIndex");
            }
        }
        #endregion

        #region 命令
        /// <summary></summary>
        public ICommand WindowLoadCommand { get; set; }
        public ICommand SkinSelectedChangedCommand { get; set; }
        #endregion

        #region 方法

        #endregion
    }
}
